package com.robmayhew.jsc;

import junit.framework.TestCase;

/**
 * Created by IntelliJ IDEA.
 * User: Rob
 * Date: 5-Apr-2005
 * Time: 8:01:03 PM
 * To change this template use File | Settings | File Templates.
 */
public class JavaSrcWordTokenizerTest
    extends TestCase
{
    public void testNormalWords() throws Exception
    {
        String oneWord = "successful";
        JavaSrcWordTokenizer jst = new JavaSrcWordTokenizer(oneWord);
        JavaSrcTokenList list = jst.getTokens();
        assertEquals("Wrong Size 1", 1, list.size());
        assertEquals("successful", oneWord, list.getToken(0).getToken());
        oneWord = "Edit this.\n";
        jst = new JavaSrcWordTokenizer(oneWord);
        list = jst.getTokens();
        assertEquals("Wrong Size 2", 2, list.size());
        assertEquals("edit", "edit", list.getToken(0).getToken());
        JavaSrcTokenListTest.assertPosition("edit", list, 0, 0, 4);
        assertEquals("this", "this", list.getToken(1).getToken());
        JavaSrcTokenListTest.assertPosition("this", list, 1, 6, 10);
        String twoWords = "Very successful";
        jst = new JavaSrcWordTokenizer(twoWords);
        list = jst.getTokens();
        assertEquals("Wrong Size 2", 2, list.size());
        assertEquals("2 words very", "very", list.getToken(0).getToken());
        assertEquals("2 Words successful", "successful", list.getToken(1).getToken());
        String loud = "I_LOVE_THIS";
        jst = new JavaSrcWordTokenizer(loud);
        list = jst.getTokens();
        assertEquals("Wrong Size 3", 3, list.size());
        assertEquals("3 Words I", "i", list.getToken(0).getToken());
        assertEquals("3 Words LOVE", "love", list.getToken(1).getToken());
        assertEquals("3 Words THIS", "this", list.getToken(2).getToken());

    }

    public void testCamelCase() throws Exception
    {
        String two = "veryGood";
        JavaSrcWordTokenizer jst = new JavaSrcWordTokenizer(two);
        JavaSrcTokenList list = jst.getTokens();
        assertEquals("Wrong Size 2", 2, list.size());
        assertEquals("very", "very", list.getToken(0).getToken());
        assertEquals("Good", "good", list.getToken(1).getToken());
        String lots = "ABCGoodStuff";
        jst = new JavaSrcWordTokenizer(lots);
        list = jst.getTokens();
        assertEquals("Wrong Size 5", 5, list.size());
        assertEquals("A", "a", list.getToken(0).getToken());
        assertEquals("B", "b", list.getToken(1).getToken());
        assertEquals("C", "c", list.getToken(2).getToken());
        assertEquals("Good", "good", list.getToken(3).getToken());
        assertEquals("Stuff", "stuff", list.getToken(4).getToken());
        String mixedUp = "testDBConnection";
        jst = new JavaSrcWordTokenizer(mixedUp);
        list = jst.getTokens();
        assertEquals("Wrong Size 4", 4, list.size());
        assertEquals("test", "test", list.getToken(0).getToken());
        assertEquals("D", "d", list.getToken(1).getToken());
        assertEquals("B", "b", list.getToken(2).getToken());
        assertEquals("Connection", "connection", list.getToken(3).getToken());
    }



    




}
